package ch.holzi.paperracers.activity;

import ch.holzi.paperracers.R;
import ch.holzi.paperracers.view.GameView;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

import android.view.Window;
import android.view.WindowManager;

/**
 * An example full-screen activity that shows and hides the system UI (i.e.
 * status bar and navigation/system bar) with user interaction.
 *
 * @see SystemUiHider
 */
public class GameWindow extends Activity {
    	
    /** A handle to the View in which the game is running. */
    private GameView mGameView;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        
        setContentView(R.layout.activity_game_window);

        mGameView = (GameView) findViewById(R.id.game);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) 
    {
        super.onPostCreate(savedInstanceState);
    }
    
    /**
     * Invoked when the Activity loses user focus.
     */
    @Override
    protected void onPause()
    {
        super.onPause();
        // TODO: save stuff into bundle here, i think...
        mGameView.getThread().pause(); // pause game when Activity pauses
        Log.d("GameWindow", "onPause() called");
    }
    
    @Override
    protected void onStart()
    {
        super.onStart();
        mGameView.createThread();
        Log.d("GameWindow", "onStart() called");
    }

    @Override
    protected void onStop()
    {
        super.onStop();
        mGameView.destroyThread();
        Log.d("GameWindow", "onStop() called");
    }
    
    @Override
    protected void onResume()
    {
        super.onResume();
        mGameView.getThread().unpause();
        Log.d("GameWindow", "onResume() called");
    }
}
